/************************************************************
 * 文件名: messageeditarea.cpp
 * 功能描述: 实现消息编辑区的具体界面与功能，包括多种消息类型的编辑与发送。
 * 作者: 李强
 * 创建日期: [请填写日期]
 * 修改历史: 
 ************************************************************/
#include "messageeditarea.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QScrollBar>

MessageEditArea::MessageEditArea(QWidget *parent)
    : QWidget{parent}
{
    //1. 设置必要的属性
    this->setFixedHeight(200);
    this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);

    //2.创建垂直方向的布局管理器
    QVBoxLayout* vlayout = new QVBoxLayout();
    vlayout->setSpacing(0);
    vlayout->setContentsMargins(10,0,10,10);
    this->setLayout(vlayout);

    //3.创建水平方向上的布局管理器
    QHBoxLayout* hlayout = new QHBoxLayout();
    hlayout->setSpacing(0);
    hlayout->setContentsMargins(10,0,0,0);
    hlayout->setAlignment(Qt::AlignLeft | Qt::AlignTop);
    vlayout->addLayout(hlayout);

    //4.把上方的四个按钮，创建好并添加到水平布局中
    QString btnStyle = "QPushButton{ background-color: rgb(245,245,245); border:none;} QPushButton:pressed { background-color: rgb(255,255,255);";
    QSize btnSize(35,35);
    QSize iconSize(25,25);

    sendImageBtn = new QPushButton();
    sendImageBtn->setFixedSize(btnSize);
    sendImageBtn->setIconSize(iconSize);
    sendImageBtn->setIcon(QIcon(":/recource/image/image.png"));
    sendImageBtn->setStyleSheet(btnStyle);
    hlayout->addWidget(sendImageBtn);

    sendFileBtn = new QPushButton();
    sendFileBtn->setFixedSize(btnSize);
    sendFileBtn->setIconSize(iconSize);
    sendFileBtn->setIcon(QIcon(":/recource/image/file.png"));
    sendFileBtn->setStyleSheet(btnStyle);
    hlayout->addWidget(sendFileBtn);

    sendSpeechBtn = new QPushButton();
    sendSpeechBtn->setFixedSize(btnSize);
    sendSpeechBtn->setIconSize(iconSize);
    sendSpeechBtn->setIcon(QIcon(":/recource/image/sound.png"));
    sendSpeechBtn->setStyleSheet(btnStyle);
    hlayout->addWidget(sendSpeechBtn);


    showHistoryBtn = new QPushButton();
    showHistoryBtn->setFixedSize(btnSize);
    showHistoryBtn->setIconSize(iconSize);
    showHistoryBtn->setIcon(QIcon(":/recource/image/history.png"));
    showHistoryBtn->setStyleSheet(btnStyle);
    hlayout->addWidget(showHistoryBtn);

    //5.添加多行编辑框
    textEdit = new QPlainTextEdit();
    textEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    textEdit->setStyleSheet("QPlainTextEdit { border:none;background-color: transparent; font-size：14px;padding: 10px;}");
    textEdit->verticalScrollBar()->setStyleSheet("QScrollBar:vertical {width:2px; background-color: rgb(45,45,45);}");
    vlayout->addWidget(textEdit);

    //6.添加发送文本消息的按钮
    sendTextBtn = new QPushButton();
    sendTextBtn->setText("发送");
    sendTextBtn->setFixedSize(120,40);
    QString style = "QPushButton {font-size: 16px; color: rgb(7,193,96); border: none; background-color:rgb(233,233,233); border-radius: 10px;}";
    style += "QPushButton:hover { background-color: rgb(210,210,210); }";
    style += "QPushButton:pressed { background-color: rgb(190,190,190); }";
    sendTextBtn->setStyleSheet(style);
    vlayout->addWidget(sendTextBtn,0,Qt::AlignRight | Qt::AlignVCenter);

}
